package org.academiadecodigo.enuminatti.helloworldspringmvc.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class DateUtils {
    public static final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");

    public static Date parse(String date) {
        if (date == null) {
            return null;
        }
        try {
            return dateFormat.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }

    public static String format(Date date) {
        if (date == null) {
            return null;
        }
        return dateFormat.format(date);
    }
}
